// UIThemeFile.cpp: implementation of the CUIThemeFile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "todolist.h"
#include "UIThemeFile.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CUIThemeFile::CUIThemeFile() : CXmlFile("TODOLIST")
{

}

CUIThemeFile::~CUIThemeFile()
{

}

BOOL CUIThemeFile::LoadThemeFile(LPCTSTR szThemeFile)
{
	if (!CXmlFile::Load(szThemeFile))
		return FALSE;

	if (!GetItem("UITHEME"))
		return FALSE;

	// else
	return TRUE;
}

void CUIThemeFile::GetTheme(UITHEME& theme) const
{
	theme.nStyle = GetStyle();

	theme.crAppBackDark = GetColor("APPBACKDARK");
	theme.crAppBackLight = GetColor("APPBACKLIGHT");
	theme.crAppLines = GetColor("APPLINES");
	//theme.crAppText = GetColor("APPTEXT");
	theme.crMenuBack = GetColor("MENUBACK");
	theme.crToolbarDark = GetColor("TOOLBARDARK");
	theme.crToolbarLight = GetColor("TOOLBARLIGHT");
	theme.crStatusBarDark = GetColor("STATUSBARDARK");
	theme.crStatusBarLight = GetColor("STATUSBARLIGHT");
}

COLORREF CUIThemeFile::GetColor(LPCTSTR szName) const
{
	const CXmlItem* pXIName = FindItem("NAME", szName);

	if (!pXIName)
		return UIT_NOCOLOR;

	const CXmlItem* pXIColor = pXIName->GetParent();
	ASSERT(pXIColor);

	BYTE bRed = (BYTE)pXIColor->GetItemValueI("R");
	BYTE bGreen = (BYTE)pXIColor->GetItemValueI("G");
	BYTE bBlue = (BYTE)pXIColor->GetItemValueI("B");

	return RGB(bRed, bGreen, bBlue);
}

UI_STYLE CUIThemeFile::GetStyle() const
{
	const CXmlItem* pXITheme = GetItem("UITHEME");
	ASSERT (pXITheme);

	if (!pXITheme)
		return UIS_GRADIENT;

	CString sStyle = pXITheme->GetItemValue("STYLE");

	if (sStyle == "GLASS")
		return UIS_GLASS;

	// else
	return UIS_GRADIENT;
}
